<?php

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/9/1
 * Time: 8:49
 */
class  classOne
{
    public function callClassOne()
    {
        echo 'classOne is function';
    }
}

//代理类ClassOneDelegator
class ClassOneDelegator
{
    private $targets;

    public function __construct()
    {
        $this->targets[] = new classOne();
    }

    public function __call($name, $arguments)
    {
        // TODO: Implement __call() method.
        foreach ($this->targets as $index => $target) {
            $re = new ReflectionClass($target);  //反射感知被代理的类
            if ($callMethod = $re->getMethod($name)) { //获得被呼叫的方法
                if ($callMethod->isPublic() && !$callMethod->isAbstract()) {  //方法是否的权限验证
                    return $callMethod->invoke($target,null);  //呼叫被代理类的方法
                }
            }
        }
    }

}
$obj=new ClassOneDelegator();
$obj->callClassOne();
